@use "sass:math";

@import "fonts";
@import "codemirror/lib/codemirror";

@import "codemirror/theme/dracula";
@import "codemirror/theme/midnight";
// TODO: remove jupyter
@import "themes/jupyter";

@import "scrollbar";
@import "ansi";

@import "./utils.scss";

@import "./pages/example-page.scss";

$secondary: #0a6df7 !default;
$mdcComponentPadding: 16px;
$codeSize: 14px;
$defaultFontSize: 15px;
$borderColor: rgba(0, 0, 0, 0.12);
$stepBorderRadius: 6px;
$mdcBorderRadius: 4px;
$dialogBackground: rgba(0, 0, 0, 0.32);

$pipelineStepHeight: 105px;
$pipelineStepWidth: 190px;

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

*:focus {
  outline: none;
}

html,
body {
  height: 100%;
}

p {
  &.padding-top {
    padding-top: var(--space-5);
  }
  &.padding-bottom {
    padding-bottom: var(--space-5);
  }
}

.float-right {
  float: right;
}

h1,
h3 {
  font-weight: 400;
}

h2 {
  font-weight: 500;
}

#root {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.header-bar {
  height: 80px;
  padding: calc(var(--space-5) / 2);
  border-bottom: 1px solid $borderColor;
  position: relative;

  .header-bar-left,
  .header-bar-actions {
    display: flex;
    align-items: center;
  }

  .header-bar-actions {
    button {
      margin-left: calc(var(--space-5) / 2);
      &:first-child {
        margin-left: 0;
      }
    }
  }

  img.logo {
    height: auto;
    box-sizing: content-box;
    width: 50px;
    padding-right: var(--space-5);
    padding-left: 10px;
    display: inline-block;
  }

  display: flex;
  justify-content: space-between;

  .pipeline-header-component {
    > div {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: row;
      width: 100%;
      height: 100%;
      position: relative;
    }

    .pipelineStatusIndicator {
      float: left;
      margin-right: 10px;
      height: 24px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-top: 1px;
    }

    button {
      position: absolute;
      right: var(--space-5);
      top: 50%;
      transform: translateY(-50%);
    }

    .pipeline-name {
      font-size: 21px;
    }
  }
}

.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;

  > main {
    overflow: hidden;
    flex: 1;
  }
}

.checkbox-tooltip-holder {
  position: relative;
  display: inline-block;

  .inline-icon {
    height: 40px;
    display: flex;
    align-items: center;
    right: calc(-1 * var(--space-5) / 2);
    top: 0;
    transform: translateX(100%);
  }
}

.custom-icon {
  &.pipeline {
    background: url("/image/pipeline.svg");
    background-repeat: no-repeat;
    background-size: contain;
    width: 43px;
    height: 24px;
    font-size: 0;
    color: transparent;
  }
}

.material-icons.inline-icon {
  position: absolute;
  &.push-left {
    margin-left: calc(var(--space-5) / 2);
  }
}

a.button {
  text-decoration: none;
  color: #000;
}

.view-page {
  &.fullheight {
    height: 100%;
  }

  &.relative {
    position: relative;
  }

  &:not(.job-view) {
    p {
      line-height: 1.5;
    }
  }

  &.orchest-settings {
    h3 {
      margin-top: var(--space-10);
      margin-bottom: calc(var(--space-5) / 2);
    }
    .CodeMirror {
      height: min-content;
    }
    .columns {
      .column {
        margin-bottom: var(--space-5);
        &:nth-child(2n) {
          padding-left: 2.5%;
        }
        &:nth-child(2n + 1) {
          padding-right: 2.5%;
        }
        .disk-size-info {
          width: 70%;
          font-weight: 500;
        }
      }
    }
  }

  &.logs-view {
    .top-buttons {
      button {
        background-color: #fff;
      }
    }
    .logs {
      display: flex;
      flex-direction: row;
      height: 100%;

      .log-title {
        font-weight: 500;
      }

      .log-section {
        line-height: 24px;
        padding: 0 8px;
        padding-bottom: calc(var(--space-5) / 2);
        i.material-icons {
          float: left;
          margin-right: 10px;
        }
      }

      .log-selector {
        width: 20%;
        min-width: 250px;
        max-width: 400px;
        padding: var(--space-5) calc(var(--space-5) / 2);
        display: flex;
        flex-direction: column;
        border-right: 1px solid $borderColor;

        i.note {
          font-size: 14px;
          padding: 8px;
        }
      }

      .log-selector-divider {
        border-bottom: 1px solid $borderColor;
        width: 100%;
        height: 0;
      }
    }
  }

  &.jupyter {
    .hiddenSession {
      display: none;
    }
  }

  .jobs-page {
    .job-actions {
      margin-bottom: var(--space-5);
    }
  }
}

.project-settings-form {
  display: flex;
  flex-direction: column;
  height: 100%;

  .project-settings {
    flex: 1;
    overflow-y: auto;
  }
}

.pipeline-settings {
  display: flex;
  flex-direction: column;
  height: 100%;

  .configuration {
    .columns {
      .column:nth-child(1) {
        width: 30%;
      }
      margin-bottom: var(--space-5);
    }
  }
  .service-form {
    h3 {
      .inline-icon {
        font-size: 22px;
      }
    }

    white-space: initial;
    .columns {
      margin-bottom: var(--space-5);
    }
  }

  .tab-view {
    flex: 1;
  }
}

.notice {
  p {
    color: #555;
    font-size: $codeSize;
  }
}

p > i.material-icons.float-left {
  float: left;
  margin-right: 10px;
}

.datetime-input {
  > div {
    margin-bottom: var(--space-5);
  }
}

.select-button-columns {
  display: flex;
}

.create-file-input {
  .field-select-combo {
    display: flex;
  }
}

.largeText {
  font-size: var(--fontSizes-xl);
  line-height: var(--lineHeights-xl);
}

.form-helper-text {
  font-size: $codeSize;
  margin-top: 10px;
}

.CodeMirror {
  font-size: $codeSize;
  border-radius: 4px;
  padding: 12px 0;
}

.xterm-holder {
  background: #000;
  padding: 0.5rem 0 0.5rem 0.5rem;
  overflow: hidden;
  border-radius: 4px;
}

.build-notice {
  font-size: $codeSize;
  display: inline-block;
  &.subtle {
    color: #555;
  }

  span.build-label {
    display: inline-block;
    min-width: 130px;
  }
}

.edit-environment {
  .xterm-holder {
    &.initializing {
      position: absolute;
      opacity: 0.01;
    }
  }
}

.jupyterlab-config-page,
.edit-environment {
  .xterm {
    height: 400px;
    width: 100%;
  }
}

.separated {
  > :last-child {
    margin-right: 0;
  }
  > * {
    margin-right: var(--space-5);
  }
}

.push-down {
  margin-bottom: var(--space-5);
}

.push-down-7 {
  margin-bottom: var(--space-7);
}

.push-up {
  margin-top: var(--space-5);
}
.push-left {
  margin-left: var(--space-5);
}
.push-right {
  margin-right: var(--space-5);
}

.push-up-half {
  margin-top: var(--space-3);
}

.persistent-view {
  flex: 1;
  display: flex;
  position: absolute;
  padding-top: 64px; // TODO: remove this hard-coded HeaderBar height
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  &.hidden {
    display: none;
  }

  &.jupyter {
    iframe {
      border: 0;
      display: block;
    }
  }
}

.file-viewer {
  .file-description,
  p {
    padding: var(--space-5);

    h3 {
      font-weight: 500;
    }
  }

  .file-description {
    border-bottom: 1px solid $borderColor;
    z-index: 9;

    .step-navigation {
      overflow: auto;
      padding-top: var(--space-5);

      .parents {
        float: left;
        button {
          margin-right: $mdcComponentPadding;
          &:last-of-type {
            margin-right: 0;
          }
        }
      }
      .children {
        float: right;
        text-align: right;

        button {
          margin-left: $mdcComponentPadding;
          &:first-of-type {
            margin-left: 0;
          }
        }
      }
      span {
        font-size: $codeSize;
        display: block;
        color: #999;
      }
    }
  }

  display: flex;
  flex-direction: column;

  .file-holder {
    flex: 1;
    flex-grow: 1;
  }

  .react-codemirror2 {
    padding: var(--space-5);

    .CodeMirror {
      width: 100%;
      height: 100%;
    }

    width: 100%;
    height: 100%;
  }
}

iframe.borderless {
  border: 0;
  display: block;
}
iframe.fullsize {
  width: 100%;
  height: 100%;
}

.hidden {
  display: none;
}

.pointer {
  cursor: pointer;
}

a.text-button,
button.text-button {
  border: 0;
  color: #000;
  text-decoration: none;
  border-bottom: 1px dotted #c6cbd1;
  background: none;
  &:hover {
    border-bottom: 1px solid black;
  }
  cursor: pointer;
}

.top-buttons {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 99;

  button {
    margin-left: 10px;
    &:first-of-type {
      margin-left: 0;
    }
  }
}

.bottom-buttons {
  background: #fff;
  width: 100%;
  margin-left: calc(-1 * var(--space-5));
  padding-left: var(--space-5);
  padding-right: var(--space-5);
  box-sizing: content-box;

  &.overflowing {
    box-shadow: 0px -9px 8px rgba(0, 0, 0, 0.05);
  }

  button {
    margin-right: var(--space-5);
    margin-top: var(--space-5);

    &:last-of-type {
      margin-right: 0;
    }
  }
}

.view-project-settings {
  ul {
    list-style-type: none;
  }

  .top-labels {
    font-size: 14px;

    a.text-button,
    button.text-button {
      font-size: 16px;
    }

    h3 {
      font-size: 21px;
    }
  }

  .project-settings {
    flex: 1;
    overflow: auto;
  }
}

.pipeline-settings-view {
  .tab-content {
    padding: var(--space-5) 0;
  }

  ul {
    list-style-type: none;
  }

  .CodeMirror {
    height: auto;
  }

  .configuration {
    form {
      button {
        margin-top: var(--space-5);
      }
    }
  }
}

.environment-properties {
  max-width: 800px;
}

.environment-variables-list {
  ul {
    list-style-type: none;
  }
}

h2.header {
  padding: var(--space-5);
  background: #f5f5f5;
  font-weight: normal;
}

.new-job {
  b {
    display: inline-block;
  }

  .steps {
    padding: var(--space-5);
  }

  .step {
    margin-bottom: var(--space-5);
  }

  .argument-set {
    margin-bottom: 5px;
  }

  .argument-label {
    display: inline-block;
  }

  .argument-values {
    display: inline-block;

    span {
      display: inline-block;
      padding: 5px;
      background: $borderColor;
      margin-left: 10px;
      cursor: pointer;
      opacity: 0.5;
      transition: 0.3s ease all;

      &.selected {
        opacity: 1;
      }
    }
  }
}

span.floating-button {
  float: left;
  display: block;
  i {
    font-size: 30px;
    padding-top: 3px;
  }

  &.pipeline-save-status {
    i {
      color: #999;
    }
  }
}

.job-view {
  display: flex;
  flex-direction: column;

  .pipeline-tab-view {
    .search {
      margin-bottom: var(--space-5);
    }
  }

  .buttons {
    background: #fff;

    button {
      margin-right: var(--space-5);

      &:last-of-type {
        margin-right: 0;
      }
    }
  }

  .pipeline-runs {
    .pipeline-run-detail {
      padding: $mdcComponentPadding;
    }
  }

  .existing-pipeline-runs {
    button {
      margin-top: var(--space-5);
    }
  }

  .tab-view {
    padding: var(--space-5) 0;
    flex: 1;
    overflow: auto;
  }

  .top-labels {
    padding-bottom: var(--space-5);
    font-size: 14px;

    h3 {
      font-size: 21px;
    }
  }
}

.warning {
  padding: calc(var(--space-5) / 2);
  border-radius: 3px;
  color: #000;
  background: var(--colors-gray200);
  font-size: 15px;

  .material-icons {
    float: left;
    margin-right: 10px;
    margin-top: -4px;
  }

  a {
    color: inherit;
  }
}

b,
strong {
  font-weight: 500;
}

.parameter-tree {
  b {
    font-weight: 500;
    display: inline-block;
    margin: 10px 0;

    &:first-of-type {
      margin-top: 0;
    }
  }

  .param-block {
    margin-bottom: 20px;

    &:last-of-type {
      margin-bottom: 0;
    }
  }

  h3 {
    margin-bottom: 10px;
  }

  .step-params {
    .parameter-key {
      margin-left: 20px;
    }
  }

  .parameter-key,
  .parameter-value {
    display: inline-block;
  }

  .parameter-row {
    margin-bottom: 5px;
  }

  .parameter-value {
    &.editable {
      color: $secondary;
      text-decoration: underline;
      cursor: pointer;
    }

    padding-left: 5px;
  }
}

.columns {
  .column {
    width: 50%;
    float: left;
    min-height: 1px;
  }
  &.three {
    .column {
      width: 33.33%;
    }
  }
  &.four {
    .column {
      width: 25%;
    }
  }
}

.command-palette-hint {
  border: 1px solid $borderColor;
  border-radius: 4px;
  padding: 5px;
  text-align: center;
  position: relative;
  user-select: none;
  cursor: pointer;
  font-size: 0.875em;
  font-weight: 500;

  .material-icons {
    position: absolute;
    left: 5px;
    font-size: 1.4em;
    margin-top: -1px;
  }

  color: #666;
}

.command-palette-holder {
  background-color: $dialogBackground;
  position: fixed;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;

  .command-pallette {
    margin-top: 20vh;
    width: 100%;
    max-width: 400px;

    .command-list {
      background: #fff;
      border-radius: $mdcBorderRadius;
      max-height: 50vh;
      overflow-y: auto;
    }
  }
}

button.themed-secondary {
  &:not(:disabled) {
    background-color: $secondary;
  }

  &:disabled {
    background: rgba(0, 0, 0, 0.12);
  }
}

.disabled-text {
  color: rgba(0, 0, 0, 0.37);
}

.fullwidth {
  width: 100%;
}

.multi-button {
  button {
    margin-left: $mdcComponentPadding;
  }

  button:first-child {
    margin-left: 0;
  }
}

.docs-notice {
  background: whitesmoke;
  border-radius: 3px;
  padding: 10px;
  color: #333;
  font-size: $defaultFontSize;

  a {
    color: $secondary;
  }
}

.pipeline-view {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: row;

  .pipeline-actions {
    position: absolute;
    right: 0;
    top: 0;
    z-index: 9;
    padding: var(--space-5);

    .services-status {
      position: absolute;
      right: 0;
      padding: var(--space-5);
      background: #fff;
      border-radius: 4px;
      box-shadow: 0 3px 4px 2px rgb(0 0 0 / 10%);
      margin: 0 var(--space-5);

      h3 {
        font-weight: 500;
        margin-bottom: calc(var(--space-5) / 2);
      }

      h4 {
        margin-top: calc(var(--space-5) / 2);
        &:first-of-type {
          margin-top: 0;
        }
      }

      .link-holder {
        i {
          display: block;
          margin-top: calc(var(--space-5) / 2);
        }
      }

      .edit-button-holder {
        border-top: 1px solid $borderColor;
        padding-top: calc(var(--space-5) / 2);
        margin-top: calc(var(--space-5) / 2);
        text-align: center;

        button {
          margin-bottom: 0;
        }
      }

      div.link-holder {
        margin-top: calc(var(--space-5) / 2);
        overflow: auto;

        a {
          color: #000;
          text-decoration: none;

          span.material-icons {
            font-size: 22px;
            float: left;
            padding-right: 8px;
            margin-top: -2px;
          }
        }
      }
    }

    button {
      min-width: 0;
    }

    &,
    .selection-buttons {
      button {
        min-width: 0;
        & + button {
          margin-left: var(--space-5);
        }
      }
    }

    &.bottom-right {
      top: auto;
      bottom: 0;
      right: 0;
      left: auto;
    }

    &.top-left {
      top: auto;
      left: 0;
      bottom: auto;
      right: auto;
    }

    &.top-right {
      button {
        margin-bottom: var(--space-5);
      }
    }

    &.bottom-left {
      top: auto;
      bottom: 0;
      right: auto;
      left: 0;

      button {
        margin-top: var(--space-5);
      }

      .navigation-buttons {
        display: inline-block;
      }

      .selection-buttons {
        display: inline-block;
        padding-left: var(--space-5);
      }
    }
  }

  .pipeline-steps-outer-holder {
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: absolute;

    &.ready-to-pan {
      cursor: grabbing; // as a fallback
      cursor: grab;
    }

    &.panning {
      cursor: grabbing;

      .pipeline-steps-holder {
        .pipeline-step {
          &:active {
            background: #fff;
          }
        }
      }
    }
  }

  .pipeline-steps-holder {
    height: 100%;
    position: absolute;
    user-select: none;
    -webkit-user-select: none;
    background-size: 40px 40px;
    background-image: url("/image/cross-fill.png");
    background-repeat: repeat;
    border: 1px solid #e5e5e5;

    .step-selector {
      position: absolute;
      z-index: 0;
      background: rgba(0, 0, 0, 0.1);
    }

    .connection {
      position: absolute;
      left: 0;
      top: 0;

      z-index: 1;

      &.selected {
        &:after {
          background-image: url("/image/arrow-head-blue.svg");
        }
      }

      &:after {
        position: absolute;
        content: " ";
        display: block;
        width: 12px;
        height: 12px;
        background-image: url("/image/arrow-head.svg");
        background-size: contain;
        background-repeat: no-repeat;
        right: 7px;
        bottom: -1px;
        transition: 0s opacity ease;
      }

      &.flipped {
        &:after {
          bottom: auto;
          top: -1px;
        }
      }

      &.flipped-horizontal {
        &:after {
          opacity: 0;
        }
      }

      pointer-events: none;

      svg {
        float: left;
        pointer-events: none;

        path {
          cursor: pointer;
          pointer-events: all;
        }
      }
    }

    .pipeline-step {
      position: absolute;
      background: #fff;
      padding: calc(var(--space-5) / 2) var(--space-5);
      border: 1px solid $borderColor;
      border-radius: $stepBorderRadius;
      cursor: pointer;
      user-select: none;
      width: $pipelineStepWidth;
      height: $pipelineStepHeight;
      text-align: center;
      z-index: 2;
      line-height: normal;

      &.hidden {
        display: none;
      }

      .execution-indicator {
        position: absolute;
        width: 100%;
        background: #eee;
        left: 0;
        bottom: 0;
        font-size: 12px;
        padding: 4px;
        color: #666;
        opacity: 1;
        border-radius: 0 0 6px 6px;
        user-select: none;
        -webkit-user-select: none;

        span.success {
          color: #16bd43;
        }
        span.failure {
          color: red;
        }
        span.aborted {
          color: orange;
        }
      }

      &.running {
        .execution-indicator {
          background: $secondary;
          color: #fff;
        }
      }

      box-shadow: 0 4px 8px -1px rgba(0, 0, 0, 0.1);

      &.selected {
        border-color: $secondary;
        background: rgb(245, 245, 255);
      }

      &:active {
        background: rgb(250, 250, 250);
      }

      &.creating-connection {
        &:active {
          background: #fff;
        }
      }

      .step-label-holder {
        display: block;
        height: 100%;
        overflow: hidden;
        transform: translateY(-11px);
        user-select: none;
        -webkit-user-select: none;
      }

      .step-label {
        text-overflow: ellipsis;
        height: calc(#{$pipelineStepHeight} - var(--space-5));
        max-height: calc(#{$pipelineStepHeight} - var(--space-5));
        width: calc(#{$pipelineStepWidth} - var(--space-5) * 2);
        max-width: calc(#{$pipelineStepWidth} - var(--space-5) * 2);
        display: table-cell;
        vertical-align: middle;
        overflow: hidden;
        font-size: $defaultFontSize;
      }
      span.filename {
        display: block;
        font-size: 14px;
        padding-top: 4px;
        color: #555;
      }

      .connection-point {
        display: block;
        width: 30px;
        height: 30px;
        border-radius: 30px;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: -16px;
        transition: left 0.3s ease;

        &.outgoing-connections {
          right: -16px;
          left: auto;
        }
      }
    }
  }

  .col-drag-resize {
    position: absolute;
    top: 0;
    height: 100%;
    width: 10px;
    margin-left: -5px;
    user-select: none;
    cursor: col-resize;
  }

  .pane {
    position: relative;

    &.pipeline-view-pane {
      flex-grow: 1;
      overflow: hidden;
    }
  }

  .pipeline-details {
    .CodeMirror {
      height: 100%;
    }

    .detail-subview {
      height: 100%;
    }

    .log-content {
      height: 100%;

      > div {
        height: 100%;
        > div.xterm {
          height: 100%;
        }
      }
    }

    .input-group {
      margin-bottom: var(--space-5);
    }

    .connection-list {
      &.dragging {
        .connection-item {
          transition: transform 0.3s ease;
        }
      }

      .connection-item {
        overflow: auto;
        padding: 10px 0;
        cursor: pointer;
        user-select: none;

        span.filename {
          color: #555;
          display: inline-block;
        }

        &.swapped-up {
          transform: translateY(-100%);
        }
        &.swapped-down {
          transform: translateY(100%);
        }

        &.selected {
          transition: none;
        }

        i.material-icons {
          float: left;
          padding-right: 10px;
          margin-top: -2px;
        }
      }
    }

    .multi-field-input {
      padding-bottom: 20px;
    }
  }
}

.multi-field-input {
  > div {
    float: left;
    width: 50%;

    &:nth-child(2) {
      width: 50%;
    }
  }
}

.clear {
  clear: both;
  display: block;
}

.commit-form {
  width: 50%;

  > div {
    width: 100%;
  }
}

.connection-form {
  width: 50%;

  > div {
    width: 100%;
  }
}

.main-content {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media only screen and (min-width: 1201px) {
  .columns {
    &.inner-padded {
      .column:nth-child(1) {
        padding-right: var(--space-5);
      }
      .column:nth-child(2) {
        padding-left: var(--space-5);
      }
    }
  }
}

@media only screen and (max-width: 1200px) {
  .view-page {
    &.orchest-settings {
      .columns {
        .column {
          &:nth-child(2n) {
            padding-left: 0;
          }
          &:nth-child(2n + 1) {
            padding-right: 0;
          }
        }
      }
    }
  }

  .columns {
    .column {
      width: 100%;
      padding: 0;
      margin-bottom: var(--space-5);
    }
    margin-bottom: 0;
  }
  .pipeline-settings .columns {
    margin-bottom: 0;
  }
}
